package com.tskj.leonsu.dao;

import com.alibaba.fastjson.JSONArray;
import com.tskj.leonsu.db.DbUtilitys;
import com.tskj.leonsu.utility.ModuleType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class OrderDAO {

    @Autowired
    private DbUtilitys dbUtilitys;

    private String getTableName(ModuleType orderType) {
        switch (orderType) {
            case DING_CAN:
                return "meal_order";
            case XI_YU:
                return "bath_order";
            case LI_FA:
                return "hair_order";
            case YU_MAO_QIU:
                return "badminton_order";
            case PING_PANG_QIU:
                return "tabletennis_order";
            case ZI_XI_SHI:
                return "study_order";
            case KUAI_DI:
                return "";
            default:
                return "";
        }
    }

    public String getAdUserName(ModuleType orderType, String orderId) {
        String tableName = getTableName(orderType);
        String sql = "select adusername from " + tableName + " where orderid=? limit 1";
        List<Map<String, Object>> list = dbUtilitys.execSQL(sql, orderId);
        if (list == null || list.size() == 0) {
            return "";
        }
        Object obj = list.get(0).get("adusername");
        if (obj == null) {
            return "";
        }
        return obj.toString();
    }

}
